#pragma once
#include <iostream>
#include <memory>

/**
 * @brief 将实现抽象成接口
 */
class IDrawAPI
{
public:
    virtual void Draw(int x, int y, int radius) = 0;
    virtual ~IDrawAPI() = default;
};

/**
 * @brief 具体实现类，实现绘制圆的功能
 */
class DrawCircle : public IDrawAPI
{
public:
    virtual void Draw(int x, int y, int radius) override
    {
        std::cout << "DrawCircle: (" << x << ", " << y << "), radius: " << radius << std::endl;
    }
};

/**
 * @brief 具体实现类，实现绘正方体的功能
 */
class DrawSquare : public IDrawAPI
{
public:
    virtual void Draw(int x, int y, int radius) override
    {
        std::cout << "DrawSquare: (" << x << ", " << y << "), radius: " << radius << std::endl;

    }
};

/**
 * @brief 形状抽象类，持有实现接口的智能指针
 */
class IShape
{
protected:
    std::unique_ptr<IDrawAPI> drawAPI;
public:
    IShape(std::unique_ptr<IDrawAPI> api) : drawAPI(std::move(api)) {}
    virtual void Draw() = 0;
    virtual ~IShape() = default;
};

class Circle : public IShape
{
public:
    Circle(int x, int y, int radius, std::unique_ptr<IDrawAPI> api)
        : IShape(std::move(api)), x(x), y(y), radius(radius) {}

    void Draw() override
    {
        drawAPI->Draw(x, y, radius);
    }
private:
    int x, y, radius;
};

class Square : public IShape
{
private:
    int x, y, length;
public:
    Square(int x, int y, int length, std::unique_ptr<IDrawAPI> api)
        : IShape(std::move(api)), x(x), y(y), length(length) {
    }

    void Draw() override
    {
        drawAPI->Draw(x, y, length);
    }
};